home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / gdb / gdb.i3 < prev    next >
Encoding:
GNU Info File  |  1994-07-26  |  41.7 KB  |  1,076 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input
  2. file gdb.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb::                         The GNU debugger.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU debugger GDB.
  8.  
  9.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  10. Source-Level Debugger' for GDB Version 4.12.
  11.  
  12.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  13. Foundation, Inc.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided also
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions.
  27.  
  28. 
  29. File: gdb.info,  Node: Thread Stops,  Prev: Signals,  Up: Stopping
  30.  
  31. Stopping and starting multi-thread programs
  32. ===========================================
  33.  
  34.    When your program has multiple threads (*note Debugging programs
  35. with multiple threads: Threads.), you can choose whether to set
  36. breakpoints on all threads, or on a particular thread.
  37.  
  38. `break LINESPEC thread THREADNO'
  39. `break LINESPEC thread THREADNO if ...'
  40.      Use the qualifier `thread THREADNO' with a breakpoint command to
  41.      specify that you only want GDB to stop the program when a
  42.      particular thread reaches this breakpoint.  THREADNO is one of the
  43.      numeric thread identifiers assigned by GDB, shown in the first
  44.      column of the `info threads' display.
  45.  
  46.      If you do not specify `thread THREADNO' when you set a breakpoint,
  47.      the breakpoint applies to *all* threads of your program.
  48.  
  49.      You can use the `thread' qualifier on conditional breakpoints as
  50.      well; in this case, place `thread THREADNO' before the breakpoint
  51.      condition, like this:
  52.  
  53.           (gdb) break frik.c:13 thread 28 if bartab > lim
  54.  
  55.    Whenever your program stops under GDB for any reason, *all* threads
  56. of execution stop, not just the current thread.  This allows you to
  57. examine the overall state of the program, including switching between
  58. threads, without worrying that things may change underfoot.
  59.  
  60.    Conversely, whenever you restart the program, *all* threads start
  61. executing.  *This is true even when single-stepping* with commands like
  62. `step' or `next'.
  63.  
  64.    In particular, GDB cannot single-step all threads in lockstep.
  65. Since thread scheduling is up to your debugging target's operating
  66. system (not controlled by GDB), other threads may execute more than one
  67. statement while the current thread completes a single step.  Moreover,
  68. in general other threads stop in the middle of a statement, rather than
  69. at a clean statement boundary, when the program stops.
  70.  
  71.    You might even find your program stopped in another thread after
  72. continuing or even single-stepping.  This happens whenever some other
  73. thread runs into a breakpoint, a signal, or an exception before the
  74. first thread completes whatever you requested.
  75.  
  76. 
  77. File: gdb.info,  Node: Stack,  Next: Source,  Prev: Stopping,  Up: Top
  78.  
  79. Examining the Stack
  80. *******************
  81.  
  82.    When your program has stopped, the first thing you need to know is
  83. where it stopped and how it got there.
  84.  
  85.    Each time your program performs a function call, the information
  86. about where in your program the call was made from is saved in a block
  87. of data called a "stack frame".  The frame also contains the arguments
  88. of the call and the local variables of the function that was called.
  89. All the stack frames are allocated in a region of memory called the
  90. "call stack".
  91.  
  92.    When your program stops, the GDB commands for examining the stack
  93. allow you to see all of this information.
  94.  
  95.    One of the stack frames is "selected" by GDB and many GDB commands
  96. refer implicitly to the selected frame.  In particular, whenever you
  97. ask GDB for the value of a variable in your program, the value is found
  98. in the selected frame.  There are special GDB commands to select
  99. whichever frame you are interested in.
  100.  
  101.    When your program stops, GDB automatically selects the currently
  102. executing frame and describes it briefly as the `frame' command does
  103. (*note Information about a frame: Frame Info.).
  104.  
  105. * Menu:
  106.  
  107. * Frames::                      Stack frames
  108. * Backtrace::                   Backtraces
  109. * Selection::                   Selecting a frame
  110. * Frame Info::                  Information on a frame
  111.  
  112. * MIPS Stack::                  MIPS machines and the function stack
  113.  
  114. 
  115. File: gdb.info,  Node: Frames,  Next: Backtrace,  Up: Stack
  116.  
  117. Stack frames
  118. ============
  119.  
  120.    The call stack is divided up into contiguous pieces called "stack
  121. frames", or "frames" for short; each frame is the data associated with
  122. one call to one function.  The frame contains the arguments given to
  123. the function, the function's local variables, and the address at which
  124. the function is executing.
  125.  
  126.    When your program is started, the stack has only one frame, that of
  127. the function `main'.  This is called the "initial" frame or the
  128. "outermost" frame.  Each time a function is called, a new frame is
  129. made.  Each time a function returns, the frame for that function
  130. invocation is eliminated.  If a function is recursive, there can be
  131. many frames for the same function.  The frame for the function in which
  132. execution is actually occurring is called the "innermost" frame.  This
  133. is the most recently created of all the stack frames that still exist.
  134.  
  135.    Inside your program, stack frames are identified by their addresses.
  136. A stack frame consists of many bytes, each of which has its own
  137. address; each kind of computer has a convention for choosing one of
  138. those bytes whose address serves as the address of the frame.  Usually
  139. this address is kept in a register called the "frame pointer register"
  140. while execution is going on in that frame.
  141.  
  142.    GDB assigns numbers to all existing stack frames, starting with zero
  143. for the innermost frame, one for the frame that called it, and so on
  144. upward.  These numbers do not really exist in your program; they are
  145. assigned by GDB to give you a way of designating stack frames in GDB
  146. commands.
  147.  
  148.    Some compilers provide a way to compile functions so that they
  149. operate without stack frames.  (For example, the `gcc' option
  150. `-fomit-frame-pointer' generates functions without a frame.) This is
  151. occasionally done with heavily used library functions to save the frame
  152. setup time.  GDB has limited facilities for dealing with these function
  153. invocations.  If the innermost function invocation has no stack frame,
  154. GDB nevertheless regards it as though it had a separate frame, which is
  155. numbered zero as usual, allowing correct tracing of the function call
  156. chain.  However, GDB has no provision for frameless functions elsewhere
  157. in the stack.
  158.  
  159. 
  160. File: gdb.info,  Node: Backtrace,  Next: Selection,  Prev: Frames,  Up: Stack
  161.  
  162. Backtraces
  163. ==========
  164.  
  165.    A backtrace is a summary of how your program got where it is.  It
  166. shows one line per frame, for many frames, starting with the currently
  167. executing frame (frame zero), followed by its caller (frame one), and
  168. on up the stack.
  169.  
  170. `backtrace'
  171. `bt'
  172.      Print a backtrace of the entire stack: one line per frame for all
  173.      frames in the stack.
  174.  
  175.      You can stop the backtrace at any time by typing the system
  176.      interrupt character, normally `C-c'.
  177.  
  178. `backtrace N'
  179. `bt N'
  180.      Similar, but print only the innermost N frames.
  181.  
  182. `backtrace -N'
  183. `bt -N'
  184.      Similar, but print only the outermost N frames.
  185.  
  186.    The names `where' and `info stack' (abbreviated `info s') are
  187. additional aliases for `backtrace'.
  188.  
  189.    Each line in the backtrace shows the frame number and the function
  190. name.  The program counter value is also shown--unless you use `set
  191. print address off'.  The backtrace also shows the source file name and
  192. line number, as well as the arguments to the function.  The program
  193. counter value is omitted if it is at the beginning of the code for that
  194. line number.
  195.  
  196.    Here is an example of a backtrace.  It was made with the command `bt
  197. 3', so it shows the innermost three frames.
  198.  
  199.      #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
  200.          at builtin.c:993
  201.      #1  0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
  202.      #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
  203.          at macro.c:71
  204.      (More stack frames follow...)
  205.  
  206. The display for frame zero does not begin with a program counter value,
  207. indicating that your program has stopped at the beginning of the code
  208. for line `993' of `builtin.c'.
  209.  
  210. 
  211. File: gdb.info,  Node: Selection,  Next: Frame Info,  Prev: Backtrace,  Up: Stack
  212.  
  213. Selecting a frame
  214. =================
  215.  
  216.    Most commands for examining the stack and other data in your program
  217. work on whichever stack frame is selected at the moment.  Here are the
  218. commands for selecting a stack frame; all of them finish by printing a
  219. brief description of the stack frame just selected.
  220.  
  221. `frame N'
  222. `f N'
  223.      Select frame number N.  Recall that frame zero is the innermost
  224.      (currently executing) frame, frame one is the frame that called the
  225.      innermost one, and so on.  The highest-numbered frame is the one
  226.      for `main'.
  227.  
  228. `frame ADDR'
  229. `f ADDR'
  230.      Select the frame at address ADDR.  This is useful mainly if the
  231.      chaining of stack frames has been damaged by a bug, making it
  232.      impossible for GDB to assign numbers properly to all frames.  In
  233.      addition, this can be useful when your program has multiple stacks
  234.      and switches between them.
  235.  
  236.      On the SPARC architecture, `frame' needs two addresses to select
  237.      an arbitrary frame: a frame pointer and a stack pointer.
  238.  
  239. `up N'
  240.      Move N frames up the stack.  For positive numbers N, this advances
  241.      toward the outermost frame, to higher frame numbers, to frames
  242.      that have existed longer.  N defaults to one.
  243.  
  244. `down N'
  245.      Move N frames down the stack.  For positive numbers N, this
  246.      advances toward the innermost frame, to lower frame numbers, to
  247.      frames that were created more recently.  N defaults to one.  You
  248.      may abbreviate `down' as `do'.
  249.  
  250.    All of these commands end by printing two lines of output describing
  251. the frame.  The first line shows the frame number, the function name,
  252. the arguments, and the source file and line number of execution in that
  253. frame.  The second line shows the text of that source line.
  254.  
  255.    For example:
  256.  
  257.      (gdb) up
  258.      #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
  259.          at env.c:10
  260.      10              read_input_file (argv[i]);
  261.  
  262.    After such a printout, the `list' command with no arguments prints
  263. ten lines centered on the point of execution in the frame.  *Note
  264. Printing source lines: List.
  265.  
  266. `up-silently N'
  267. `down-silently N'
  268.      These two commands are variants of `up' and `down', respectively;
  269.      they differ in that they do their work silently, without causing
  270.      display of the new frame.  They are intended primarily for use in
  271.      GDB command scripts, where the output might be unnecessary and
  272.      distracting.
  273.  
  274. 
  275. File: gdb.info,  Node: Frame Info,  Next: MIPS Stack,  Prev: Selection,  Up: Stack
  276.  
  277. Information about a frame
  278. =========================
  279.  
  280.    There are several other commands to print information about the
  281. selected stack frame.
  282.  
  283. `frame'
  284. `f'
  285.      When used without any argument, this command does not change which
  286.      frame is selected, but prints a brief description of the currently
  287.      selected stack frame.  It can be abbreviated `f'.  With an
  288.      argument, this command is used to select a stack frame.  *Note
  289.      Selecting a frame: Selection.
  290.  
  291. `info frame'
  292. `info f'
  293.      This command prints a verbose description of the selected stack
  294.      frame, including the address of the frame, the addresses of the
  295.      next frame down (called by this frame) and the next frame up
  296.      (caller of this frame), the language that the source code
  297.      corresponding to this frame was written in, the address of the
  298.      frame's arguments, the program counter saved in it (the address of
  299.      execution in the caller frame), and which registers were saved in
  300.      the frame.  The verbose description is useful when something has
  301.      gone wrong that has made the stack format fail to fit the usual
  302.      conventions.
  303.  
  304. `info frame ADDR'
  305. `info f ADDR'
  306.      Print a verbose description of the frame at address ADDR, without
  307.      selecting that frame.  The selected frame remains unchanged by
  308.      this command.
  309.  
  310. `info args'
  311.      Print the arguments of the selected frame, each on a separate line.
  312.  
  313. `info locals'
  314.      Print the local variables of the selected frame, each on a separate
  315.      line.  These are all variables (declared either static or
  316.      automatic) accessible at the point of execution of the selected
  317.      frame.
  318.  
  319. `info catch'
  320.      Print a list of all the exception handlers that are active in the
  321.      current stack frame at the current point of execution.  To see
  322.      other exception handlers, visit the associated frame (using the
  323.      `up', `down', or `frame' commands); then type `info catch'.  *Note
  324.      Breakpoints and exceptions: Exception Handling.
  325.  
  326. 
  327. File: gdb.info,  Node: MIPS Stack,  Prev: Frame Info,  Up: Stack
  328.  
  329. MIPS machines and the function stack
  330. ====================================
  331.  
  332.    MIPS based computers use an unusual stack frame, which sometimes
  333. requires GDB to search backward in the object code to find the
  334. beginning of a function.
  335.  
  336.    To improve response time (especially for embedded applications, where
  337. GDB may be restricted to a slow serial line for this search) you may
  338. want to limit the size of this search, using one of these commands:
  339.  
  340. `set heuristic-fence-post LIMIT'
  341.      Restrict GDB to examining at most LIMIT bytes in its search for
  342.      the beginning of a function.  A value of `0' (the default) means
  343.      there is no limit.
  344.  
  345. `show heuristic-fence-post'
  346.      Display the current limit.
  347.  
  348. These commands are available *only* when GDB is configured for
  349. debugging programs on MIPS processors.
  350.  
  351. 
  352. File: gdb.info,  Node: Source,  Next: Data,  Prev: Stack,  Up: Top
  353.  
  354. Examining Source Files
  355. **********************
  356.  
  357.    GDB can print parts of your program's source, since the debugging
  358. information recorded in the program tells GDB what source files were
  359. used to build it.  When your program stops, GDB spontaneously prints
  360. the line where it stopped.  Likewise, when you select a stack frame
  361. (*note Selecting a frame: Selection.), GDB prints the line where
  362. execution in that frame has stopped.  You can print other portions of
  363. source files by explicit command.
  364.  
  365.    If you use GDB through its GNU Emacs interface, you may prefer to use
  366. Emacs facilities to view source; *note Using GDB under GNU Emacs:
  367. Emacs..
  368.  
  369. * Menu:
  370.  
  371. * List::                        Printing source lines
  372.  
  373. * Search::                      Searching source files
  374.  
  375. * Source Path::                 Specifying source directories
  376. * Machine Code::                Source and machine code
  377.  
  378. 
  379. File: gdb.info,  Node: List,  Next: Search,  Up: Source
  380.  
  381. Printing source lines
  382. =====================
  383.  
  384.    To print lines from a source file, use the `list' command
  385. (abbreviated `l').  There are several ways to specify what part of the
  386. file you want to print.
  387.  
  388.    Here are the forms of the `list' command most commonly used:
  389.  
  390. `list LINENUM'
  391.      Print lines centered around line number LINENUM in the current
  392.      source file.
  393.  
  394. `list FUNCTION'
  395.      Print lines centered around the beginning of function FUNCTION.
  396.  
  397. `list'
  398.      Print more lines.  If the last lines printed were printed with a
  399.      `list' command, this prints lines following the last lines
  400.      printed; however, if the last line printed was a solitary line
  401.      printed as part of displaying a stack frame (*note Examining the
  402.      Stack: Stack.), this prints lines centered around that line.
  403.  
  404. `list -'
  405.      Print lines just before the lines last printed.
  406.  
  407.    By default, GDB prints ten source lines with any of these forms of
  408. the `list' command.  You can change this using `set listsize':
  409.  
  410. `set listsize COUNT'
  411.      Make the `list' command display COUNT source lines (unless the
  412.      `list' argument explicitly specifies some other number).
  413.  
  414. `show listsize'
  415.      Display the number of lines that `list' prints.
  416.  
  417.    Repeating a `list' command with RET discards the argument, so it is
  418. equivalent to typing just `list'.  This is more useful than listing the
  419. same lines again.  An exception is made for an argument of `-'; that
  420. argument is preserved in repetition so that each repetition moves up in
  421. the source file.
  422.  
  423.    In general, the `list' command expects you to supply zero, one or two
  424. "linespecs".  Linespecs specify source lines; there are several ways of
  425. writing them but the effect is always to specify some source line.
  426. Here is a complete description of the possible arguments for `list':
  427.  
  428. `list LINESPEC'
  429.      Print lines centered around the line specified by LINESPEC.
  430.  
  431. `list FIRST,LAST'
  432.      Print lines from FIRST to LAST.  Both arguments are linespecs.
  433.  
  434. `list ,LAST'
  435.      Print lines ending with LAST.
  436.  
  437. `list FIRST,'
  438.      Print lines starting with FIRST.
  439.  
  440. `list +'
  441.      Print lines just after the lines last printed.
  442.  
  443. `list -'
  444.      Print lines just before the lines last printed.
  445.  
  446. `list'
  447.      As described in the preceding table.
  448.  
  449.    Here are the ways of specifying a single source line--all the kinds
  450. of linespec.
  451.  
  452. `NUMBER'
  453.      Specifies line NUMBER of the current source file.  When a `list'
  454.      command has two linespecs, this refers to the same source file as
  455.      the first linespec.
  456.  
  457. `+OFFSET'
  458.      Specifies the line OFFSET lines after the last line printed.  When
  459.      used as the second linespec in a `list' command that has two, this
  460.      specifies the line OFFSET lines down from the first linespec.
  461.  
  462. `-OFFSET'
  463.      Specifies the line OFFSET lines before the last line printed.
  464.  
  465. `FILENAME:NUMBER'
  466.      Specifies line NUMBER in the source file FILENAME.
  467.  
  468. `FUNCTION'
  469.      Specifies the line of the open-brace that begins the body of the
  470.      function FUNCTION.
  471.  
  472. `FILENAME:FUNCTION'
  473.      Specifies the line of the open-brace that begins the body of the
  474.      function FUNCTION in the file FILENAME.  You only need the file
  475.      name with a function name to avoid ambiguity when there are
  476.      identically named functions in different source files.
  477.  
  478. `*ADDRESS'
  479.      Specifies the line containing the program address ADDRESS.
  480.      ADDRESS may be any expression.
  481.  
  482. 
  483. File: gdb.info,  Node: Search,  Next: Source Path,  Prev: List,  Up: Source
  484.  
  485. Searching source files
  486. ======================
  487.  
  488.    There are two commands for searching through the current source file
  489. for a regular expression.
  490.  
  491. `forward-search REGEXP'
  492. `search REGEXP'
  493.      The command `forward-search REGEXP' checks each line, starting
  494.      with the one following the last line listed, for a match for
  495.      REGEXP.  It lists the line that is found.  You can use synonym
  496.      `search REGEXP' or abbreviate the command name as `fo'.
  497.  
  498. `reverse-search REGEXP'
  499.      The command `reverse-search REGEXP' checks each line, starting
  500.      with the one before the last line listed and going backward, for a
  501.      match for REGEXP.  It lists the line that is found.  You can
  502.      abbreviate this command as `rev'.
  503.  
  504. 
  505. File: gdb.info,  Node: Source Path,  Next: Machine Code,  Prev: Search,  Up: Source
  506.  
  507. Specifying source directories
  508. =============================
  509.  
  510.    Executable programs sometimes do not record the directories of the
  511. source files from which they were compiled, just the names.  Even when
  512. they do, the directories could be moved between the compilation and
  513. your debugging session.  GDB has a list of directories to search for
  514. source files; this is called the "source path".  Each time GDB wants a
  515. source file, it tries all the directories in the list, in the order
  516. they are present in the list, until it finds a file with the desired
  517. name.  Note that the executable search path is *not* used for this
  518. purpose.  Neither is the current working directory, unless it happens
  519. to be in the source path.
  520.  
  521.    If GDB cannot find a source file in the source path, and the object
  522. program records a directory, GDB tries that directory too.  If the
  523. source path is empty, and there is no record of the compilation
  524. directory, GDB looks in the current directory as a last resort.
  525.  
  526.    Whenever you reset or rearrange the source path, GDB clears out any
  527. information it has cached about where source files are found and where
  528. each line is in the file.
  529.  
  530.    When you start GDB, its source path is empty.  To add other
  531. directories, use the `directory' command.
  532.  
  533. `directory DIRNAME ...'
  534.      Add directory DIRNAME to the front of the source path.  Several
  535.      directory names may be given to this command, separated by `:' or
  536.      whitespace.  You may specify a directory that is already in the
  537.      source path; this moves it forward, so GDB searches it sooner.
  538.  
  539.      You can use the string `$cdir' to refer to the compilation
  540.      directory (if one is recorded), and `$cwd' to refer to the current
  541.      working directory.  `$cwd' is not the same as `.'--the former
  542.      tracks the current working directory as it changes during your GDB
  543.      session, while the latter is immediately expanded to the current
  544.      directory at the time you add an entry to the source path.
  545.  
  546. `directory'
  547.      Reset the source path to empty again.  This requires confirmation.
  548.  
  549. `show directories'
  550.      Print the source path: show which directories it contains.
  551.  
  552.    If your source path is cluttered with directories that are no longer
  553. of interest, GDB may sometimes cause confusion by finding the wrong
  554. versions of source.  You can correct the situation as follows:
  555.  
  556.   1. Use `directory' with no argument to reset the source path to empty.
  557.  
  558.   2. Use `directory' with suitable arguments to reinstall the
  559.      directories you want in the source path.  You can add all the
  560.      directories in one command.
  561.  
  562. 
  563. File: gdb.info,  Node: Machine Code,  Prev: Source Path,  Up: Source
  564.  
  565. Source and machine code
  566. =======================
  567.  
  568.    You can use the command `info line' to map source lines to program
  569. addresses (and vice versa), and the command `disassemble' to display a
  570. range of addresses as machine instructions.
  571.  
  572. `info line LINESPEC'
  573.      Print the starting and ending addresses of the compiled code for
  574.      source line LINESPEC.  You can specify source lines in any of the
  575.      ways understood by the `list' command (*note Printing source
  576.      lines: List.).
  577.  
  578.    For example, we can use `info line' to discover the location of the
  579. object code for the first line of function `m4_changequote':
  580.  
  581.      (gdb) info line m4_changecom
  582.      Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
  583.  
  584. We can also inquire (using `*ADDR' as the form for LINESPEC) what
  585. source line covers a particular address:
  586.      (gdb) info line *0x63ff
  587.      Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
  588.  
  589.    After `info line', the default address for the `x' command is
  590. changed to the starting address of the line, so that `x/i' is
  591. sufficient to begin examining the machine code (*note Examining memory:
  592. Memory.).  Also, this address is saved as the value of the convenience
  593. variable `$_' (*note Convenience variables: Convenience Vars.).
  594.  
  595. `disassemble'
  596.      This specialized command dumps a range of memory as machine
  597.      instructions.  The default memory range is the function
  598.      surrounding the program counter of the selected frame.  A single
  599.      argument to this command is a program counter value; GDB dumps the
  600.      function surrounding this value.  Two arguments specify a range of
  601.      addresses (first inclusive, second exclusive) to dump.
  602.  
  603.    We can use `disassemble' to inspect the object code range shown in
  604. the last `info line' example (the example shows SPARC machine
  605. instructions):
  606.  
  607.      (gdb) disas 0x63e4 0x6404
  608.      Dump of assembler code from 0x63e4 to 0x6404:
  609.      0x63e4 <builtin_init+5340>:     ble 0x63f8 <builtin_init+5360>
  610.      0x63e8 <builtin_init+5344>:     sethi %hi(0x4c00), %o0
  611.      0x63ec <builtin_init+5348>:     ld [%i1+4], %o0
  612.      0x63f0 <builtin_init+5352>:     b 0x63fc <builtin_init+5364>
  613.      0x63f4 <builtin_init+5356>:     ld [%o0+4], %o0
  614.      0x63f8 <builtin_init+5360>:     or %o0, 0x1a4, %o0
  615.      0x63fc <builtin_init+5364>:     call 0x9288 <path_search>
  616.      0x6400 <builtin_init+5368>:     nop
  617.      End of assembler dump.
  618.  
  619. 
  620. File: gdb.info,  Node: Data,  Next: Languages,  Prev: Source,  Up: Top
  621.  
  622. Examining Data
  623. **************
  624.  
  625.    The usual way to examine data in your program is with the `print'
  626. command (abbreviated `p'), or its synonym `inspect'.  It evaluates and
  627. prints the value of an expression of the language your program is
  628. written in (*note Using GDB with Different Languages: Languages.).
  629.  
  630. `print EXP'
  631. `print /F EXP'
  632.      EXP is an expression (in the source language).  By default the
  633.      value of EXP is printed in a format appropriate to its data type;
  634.      you can choose a different format by specifying `/F', where F is a
  635.      letter specifying the format; *note Output formats: Output
  636.      Formats..
  637.  
  638. `print'
  639. `print /F'
  640.      If you omit EXP, GDB displays the last value again (from the
  641.      "value history"; *note Value history: Value History.).  This
  642.      allows you to conveniently inspect the same value in an
  643.      alternative format.
  644.  
  645.    A more low-level way of examining data is with the `x' command.  It
  646. examines data in memory at a specified address and prints it in a
  647. specified format.  *Note Examining memory: Memory.
  648.  
  649.    If you are interested in information about types, or about how the
  650. fields of a struct or class are declared, use the `ptype EXP' command
  651. rather than `print'. *Note Examining the Symbol Table: Symbols.
  652.  
  653. * Menu:
  654.  
  655. * Expressions::                 Expressions
  656. * Variables::                   Program variables
  657. * Arrays::                      Artificial arrays
  658. * Output Formats::              Output formats
  659. * Memory::                      Examining memory
  660. * Auto Display::                Automatic display
  661. * Print Settings::              Print settings
  662. * Value History::               Value history
  663. * Convenience Vars::            Convenience variables
  664. * Registers::                   Registers
  665.  
  666. * Floating Point Hardware::     Floating point hardware
  667.  
  668. 
  669. File: gdb.info,  Node: Expressions,  Next: Variables,  Up: Data
  670.  
  671. Expressions
  672. ===========
  673.  
  674.    `print' and many other GDB commands accept an expression and compute
  675. its value.  Any kind of constant, variable or operator defined by the
  676. programming language you are using is valid in an expression in GDB.
  677. This includes conditional expressions, function calls, casts and string
  678. constants.  It unfortunately does not include symbols defined by
  679. preprocessor `#define' commands.
  680.  
  681.    Because C is so widespread, most of the expressions shown in
  682. examples in this manual are in C.  *Note Using GDB with Different
  683. Languages: Languages, for information on how to use expressions in other
  684. languages.
  685.  
  686.    In this section, we discuss operators that you can use in GDB
  687. expressions regardless of your programming language.
  688.  
  689.    Casts are supported in all languages, not just in C, because it is so
  690. useful to cast a number into a pointer so as to examine a structure at
  691. that address in memory.
  692.  
  693.    GDB supports these operators in addition to those of programming
  694. languages:
  695.  
  696. `@'
  697.      `@' is a binary operator for treating parts of memory as arrays.
  698.      *Note Artificial arrays: Arrays, for more information.
  699.  
  700. `::'
  701.      `::' allows you to specify a variable in terms of the file or
  702.      function where it is defined.  *Note Program variables: Variables.
  703.  
  704. `{TYPE} ADDR'
  705.      Refers to an object of type TYPE stored at address ADDR in memory.
  706.      ADDR may be any expression whose value is an integer or pointer
  707.      (but parentheses are required around binary operators, just as in
  708.      a cast).  This construct is allowed regardless of what kind of
  709.      data is normally supposed to reside at ADDR.
  710.  
  711. 
  712. File: gdb.info,  Node: Variables,  Next: Arrays,  Prev: Expressions,  Up: Data
  713.  
  714. Program variables
  715. =================
  716.  
  717.    The most common kind of expression to use is the name of a variable
  718. in your program.
  719.  
  720.    Variables in expressions are understood in the selected stack frame
  721. (*note Selecting a frame: Selection.); they must either be global (or
  722. static) or be visible according to the scope rules of the programming
  723. language from the point of execution in that frame.  This means that in
  724. the function
  725.  
  726.      foo (a)
  727.           int a;
  728.      {
  729.        bar (a);
  730.        {
  731.          int b = test ();
  732.          bar (b);
  733.        }
  734.      }
  735.  
  736. you can examine and use the variable `a' whenever your program is
  737. executing within the function `foo', but you can only use or examine
  738. the variable `b' while your program is executing inside the block where
  739. `b' is declared.
  740.  
  741.    There is an exception: you can refer to a variable or function whose
  742. scope is a single source file even if the current execution point is not
  743. in this file.  But it is possible to have more than one such variable or
  744. function with the same name (in different source files).  If that
  745. happens, referring to that name has unpredictable effects.  If you wish,
  746. you can specify a static variable in a particular function or file,
  747. using the colon-colon notation:
  748.  
  749.      FILE::VARIABLE
  750.      FUNCTION::VARIABLE
  751.  
  752. Here FILE or FUNCTION is the name of the context for the static
  753. VARIABLE.  In the case of file names, you can use quotes to make sure
  754. GDB parses the file name as a single word--for example, to print a
  755. global value of `x' defined in `f2.c':
  756.  
  757.      (gdb) p 'f2.c'::x
  758.  
  759.    This use of `::' is very rarely in conflict with the very similar
  760. use of the same notation in C++.  GDB also supports use of the C++
  761. scope resolution operator in GDB expressions.
  762.  
  763.      *Warning:* Occasionally, a local variable may appear to have the
  764.      wrong value at certain points in a function--just after entry to a
  765.      new scope, and just before exit.
  766.    You may see this problem when you are stepping by machine
  767. instructions.  This is because on most machines, it takes more than one
  768. instruction to set up a stack frame (including local variable
  769. definitions); if you are stepping by machine instructions, variables
  770. may appear to have the wrong values until the stack frame is completely
  771. built.  On exit, it usually also takes more than one machine
  772. instruction to destroy a stack frame; after you begin stepping through
  773. that group of instructions, local variable definitions may be gone.
  774.  
  775. 
  776. File: gdb.info,  Node: Arrays,  Next: Output Formats,  Prev: Variables,  Up: Data
  777.  
  778. Artificial arrays
  779. =================
  780.  
  781.    It is often useful to print out several successive objects of the
  782. same type in memory; a section of an array, or an array of dynamically
  783. determined size for which only a pointer exists in the program.
  784.  
  785.    You can do this by referring to a contiguous span of memory as an
  786. "artificial array", using the binary operator `@'.  The left operand of
  787. `@' should be the first element of the desired array, as an individual
  788. object.  The right operand should be the desired length of the array.
  789. The result is an array value whose elements are all of the type of the
  790. left argument.  The first element is actually the left argument; the
  791. second element comes from bytes of memory immediately following those
  792. that hold the first element, and so on.  Here is an example.  If a
  793. program says
  794.  
  795.      int *array = (int *) malloc (len * sizeof (int));
  796.  
  797. you can print the contents of `array' with
  798.  
  799.      p *array@len
  800.  
  801.    The left operand of `@' must reside in memory.  Array values made
  802. with `@' in this way behave just like other arrays in terms of
  803. subscripting, and are coerced to pointers when used in expressions.
  804. Artificial arrays most often appear in expressions via the value history
  805. (*note Value history: Value History.), after printing one out.
  806.  
  807.    Sometimes the artificial array mechanism is not quite enough; in
  808. moderately complex data structures, the elements of interest may not
  809. actually be adjacent--for example, if you are interested in the values
  810. of pointers in an array.  One useful work-around in this situation is
  811. to use a convenience variable (*note Convenience variables: Convenience
  812. Vars.) as a counter in an expression that prints the first interesting
  813. value, and then repeat that expression via RET.  For instance, suppose
  814. you have an array `dtab' of pointers to structures, and you are
  815. interested in the values of a field `fv' in each structure.  Here is an
  816. example of what you might type:
  817.  
  818.      set $i = 0
  819.      p dtab[$i++]->fv
  820.      RET
  821.      RET
  822.      ...
  823.  
  824. 
  825. File: gdb.info,  Node: Output Formats,  Next: Memory,  Prev: Arrays,  Up: Data
  826.  
  827. Output formats
  828. ==============
  829.  
  830.    By default, GDB prints a value according to its data type.  Sometimes
  831. this is not what you want.  For example, you might want to print a
  832. number in hex, or a pointer in decimal.  Or you might want to view data
  833. in memory at a certain address as a character string or as an
  834. instruction.  To do these things, specify an "output format" when you
  835. print a value.
  836.  
  837.    The simplest use of output formats is to say how to print a value
  838. already computed.  This is done by starting the arguments of the
  839. `print' command with a slash and a format letter.  The format letters
  840. supported are:
  841.  
  842. `x'
  843.      Regard the bits of the value as an integer, and print the integer
  844.      in hexadecimal.
  845.  
  846. `d'
  847.      Print as integer in signed decimal.
  848.  
  849. `u'
  850.      Print as integer in unsigned decimal.
  851.  
  852. `o'
  853.      Print as integer in octal.
  854.  
  855. `t'
  856.      Print as integer in binary.  The letter `t' stands for "two".  (1)
  857.  
  858. `a'
  859.      Print as an address, both absolute in hexadecimal and as an offset
  860.      from the nearest preceding symbol.  You can use this format used
  861.      to discover where (in what function) an unknown address is located:
  862.  
  863.           (gdb) p/a 0x54320
  864.           $3 = 0x54320 <_initialize_vx+396>
  865.  
  866. `c'
  867.      Regard as an integer and print it as a character constant.
  868.  
  869. `f'
  870.      Regard the bits of the value as a floating point number and print
  871.      using typical floating point syntax.
  872.  
  873.    For example, to print the program counter in hex (*note
  874. Registers::.), type
  875.  
  876.      p/x $pc
  877.  
  878. Note that no space is required before the slash; this is because command
  879. names in GDB cannot contain a slash.
  880.  
  881.    To reprint the last value in the value history with a different
  882. format, you can use the `print' command with just a format and no
  883. expression.  For example, `p/x' reprints the last value in hex.
  884.  
  885.    ---------- Footnotes ----------
  886.  
  887.    (1)  `b' cannot be used because these format letters are also used
  888. with the `x' command, where `b' stands for "byte"; *note Examining
  889. memory: Memory..
  890.  
  891. 
  892. File: gdb.info,  Node: Memory,  Next: Auto Display,  Prev: Output Formats,  Up: Data
  893.  
  894. Examining memory
  895. ================
  896.  
  897.    You can use the command `x' (for "examine") to examine memory in any
  898. of several formats, independently of your program's data types.
  899.  
  900. `x/NFU ADDR'
  901. `x ADDR'
  902. `x'
  903.      Use the `x' command to examine memory.
  904.  
  905.    N, F, and U are all optional parameters that specify how much memory
  906. to display and how to format it; ADDR is an expression giving the
  907. address where you want to start displaying memory.  If you use defaults
  908. for NFU, you need not type the slash `/'.  Several commands set
  909. convenient defaults for ADDR.
  910.  
  911. N, the repeat count
  912.      The repeat count is a decimal integer; the default is 1.  It
  913.      specifies how much memory (counting by units U) to display.
  914.  
  915. F, the display format
  916.      The display format is one of the formats used by `print', or `s'
  917.      (null-terminated string) or `i' (machine instruction).  The
  918.      default is `x' (hexadecimal) initially, or the format from the
  919.      last time you used either `x' or `print'.
  920.  
  921. U, the unit size
  922.      The unit size is any of
  923.  
  924.     `b'
  925.           Bytes.
  926.  
  927.     `h'
  928.           Halfwords (two bytes).
  929.  
  930.     `w'
  931.           Words (four bytes).  This is the initial default.
  932.  
  933.     `g'
  934.           Giant words (eight bytes).
  935.  
  936.      Each time you specify a unit size with `x', that size becomes the
  937.      default unit the next time you use `x'.  (For the `s' and `i'
  938.      formats, the unit size is ignored and is normally not written.)
  939.  
  940. ADDR, starting display address
  941.      ADDR is the address where you want GDB to begin displaying memory.
  942.      The expression need not have a pointer value (though it may); it
  943.      is always interpreted as an integer address of a byte of memory.
  944.      *Note Expressions: Expressions, for more information on
  945.      expressions.  The default for ADDR is usually just after the last
  946.      address examined--but several other commands also set the default
  947.      address: `info breakpoints' (to the address of the last breakpoint
  948.      listed), `info line' (to the starting address of a line), and
  949.      `print' (if you use it to display a value from memory).
  950.  
  951.    For example, `x/3uh 0x54320' is a request to display three halfwords
  952. (`h') of memory, formatted as unsigned decimal integers (`u'), starting
  953. at address `0x54320'.  `x/4xw $sp' prints the four words (`w') of
  954. memory above the stack pointer (here, `$sp'; *note Registers::.) in
  955. hexadecimal (`x').
  956.  
  957.    Since the letters indicating unit sizes are all distinct from the
  958. letters specifying output formats, you do not have to remember whether
  959. unit size or format comes first; either order works.  The output
  960. specifications `4xw' and `4wx' mean exactly the same thing.  (However,
  961. the count N must come first; `wx4' does not work.)
  962.  
  963.    Even though the unit size U is ignored for the formats `s' and `i',
  964. you might still want to use a count N; for example, `3i' specifies that
  965. you want to see three machine instructions, including any operands.
  966. The command `disassemble' gives an alternative way of inspecting
  967. machine instructions; *note Source and machine code: Machine Code..
  968.  
  969.    All the defaults for the arguments to `x' are designed to make it
  970. easy to continue scanning memory with minimal specifications each time
  971. you use `x'.  For example, after you have inspected three machine
  972. instructions with `x/3i ADDR', you can inspect the next seven with just
  973. `x/7'.  If you use RET to repeat the `x' command, the repeat count N is
  974. used again; the other arguments default as for successive uses of `x'.
  975.  
  976.    The addresses and contents printed by the `x' command are not saved
  977. in the value history because there is often too much of them and they
  978. would get in the way.  Instead, GDB makes these values available for
  979. subsequent use in expressions as values of the convenience variables
  980. `$_' and `$__'.  After an `x' command, the last address examined is
  981. available for use in expressions in the convenience variable `$_'.  The
  982. contents of that address, as examined, are available in the convenience
  983. variable `$__'.
  984.  
  985.    If the `x' command has a repeat count, the address and contents saved
  986. are from the last memory unit printed; this is not the same as the last
  987. address printed if several units were printed on the last line of
  988. output.
  989.  
  990. 
  991. File: gdb.info,  Node: Auto Display,  Next: Print Settings,  Prev: Memory,  Up: Data
  992.  
  993. Automatic display
  994. =================
  995.  
  996.    If you find that you want to print the value of an expression
  997. frequently (to see how it changes), you might want to add it to the
  998. "automatic display list" so that GDB prints its value each time your
  999. program stops.  Each expression added to the list is given a number to
  1000. identify it; to remove an expression from the list, you specify that
  1001. number.  The automatic display looks like this:
  1002.  
  1003.      2: foo = 38
  1004.      3: bar[5] = (struct hack *) 0x3804
  1005.  
  1006. This display shows item numbers, expressions and their current values.
  1007. As with displays you request manually using `x' or `print', you can
  1008. specify the output format you prefer; in fact, `display' decides
  1009. whether to use `print' or `x' depending on how elaborate your format
  1010. specification is--it uses `x' if you specify a unit size, or one of the
  1011. two formats (`i' and `s') that are only supported by `x'; otherwise it
  1012. uses `print'.
  1013.  
  1014. `display EXP'
  1015.      Add the expression EXP to the list of expressions to display each
  1016.      time your program stops.  *Note Expressions: Expressions.
  1017.  
  1018.      `display' does not repeat if you press RET again after using it.
  1019.  
  1020. `display/FMT EXP'
  1021.      For FMT specifying only a display format and not a size or count,
  1022.      add the expression EXP to the auto-display list but arrange to
  1023.      display it each time in the specified format FMT.  *Note Output
  1024.      formats: Output Formats.
  1025.  
  1026. `display/FMT ADDR'
  1027.      For FMT `i' or `s', or including a unit-size or a number of units,
  1028.      add the expression ADDR as a memory address to be examined each
  1029.      time your program stops.  Examining means in effect doing `x/FMT
  1030.      ADDR'.  *Note Examining memory: Memory.
  1031.  
  1032.    For example, `display/i $pc' can be helpful, to see the machine
  1033. instruction about to be executed each time execution stops (`$pc' is a
  1034. common name for the program counter; *note Registers::.).
  1035.  
  1036. `undisplay DNUMS...'
  1037. `delete display DNUMS...'
  1038.      Remove item numbers DNUMS from the list of expressions to display.
  1039.  
  1040.      `undisplay' does not repeat if you press RET after using it.
  1041.      (Otherwise you would just get the error `No display number ...'.)
  1042.  
  1043. `disable display DNUMS...'
  1044.      Disable the display of item numbers DNUMS.  A disabled display
  1045.      item is not printed automatically, but is not forgotten.  It may be
  1046.      enabled again later.
  1047.  
  1048. `enable display DNUMS...'
  1049.      Enable display of item numbers DNUMS.  It becomes effective once
  1050.      again in auto display of its expression, until you specify
  1051.      otherwise.
  1052.  
  1053. `display'
  1054.      Display the current values of the expressions on the list, just as
  1055.      is done when your program stops.
  1056.  
  1057. `info display'
  1058.      Print the list of expressions previously set up to display
  1059.      automatically, each one with its item number, but without showing
  1060.      the values.  This includes disabled expressions, which are marked
  1061.      as such.  It also includes expressions which would not be
  1062.      displayed right now because they refer to automatic variables not
  1063.      currently available.
  1064.  
  1065.    If a display expression refers to local variables, then it does not
  1066. make sense outside the lexical context for which it was set up.  Such an
  1067. expression is disabled when execution enters a context where one of its
  1068. variables is not defined.  For example, if you give the command
  1069. `display last_char' while inside a function with an argument
  1070. `last_char', GDB displays this argument while your program continues to
  1071. stop inside that function.  When it stops elsewhere--where there is no
  1072. variable `last_char'--the display is disabled automatically.  The next
  1073. time your program stops where `last_char' is meaningful, you can enable
  1074. the display expression once again.
  1075.  
  1076.